﻿using AutoMapper;
using MediatR;
using S.Breeding.Api.Application.Command.LambWeaningCommand;
using S.Breeding.Domain;
using S.Breeding.Infrastructure;

namespace S.Breeding.Api.Application.CommandHandlers.LambWeaningCommandHandlers
{
    public class LambWeaningBatchCommandHandlers : IRequestHandler<LambWeaningBatchCommand, int>
    {
        private readonly IRepository<LambWeaning> repository;
        private readonly IMapper mapper;
        public LambWeaningBatchCommandHandlers(IRepository<LambWeaning> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(LambWeaningBatchCommand request, CancellationToken cancellationToken)
        {
            string[] ids = request.Array.ToString().Split(',');
            foreach (var item in ids)
            {
                await repository.DeleteAsync(int.Parse(item));
            }
            return 1;
        }
    }
}
